<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseMedicalPerceptions {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_intCasePaperId;
	protected $m_intDepartmentId;
	protected $m_intDoctorId;
	protected $m_intDiagnosisId;
	protected $m_strNextVisitDate;
	protected $m_strMedicianName;
	protected $m_intQuantity;
	protected $m_strComapanyName;
	protected $m_strNote;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getCasePaperId(){
		return $this->m_intCasePaperId;
	}

	public function getDepartmentId(){
		return $this->m_intDepartmentId;
	}

	public function getDoctorId(){
		return $this->m_intDoctorId;
	}

	public function getDiagnosisId(){
		return $this->m_intDiagnosisId;
	}

	public function getNextVisitDate(){
		return $this->m_strNextVisitDate;
	}

	public function getMedicianName(){
		return $this->m_strMedicianName;
	}

	public function getQuantity(){
		return $this->m_intQuantity;
	}

	public function getComapanyName(){
		return $this->m_strComapanyName;
	}

	public function getNote(){
		return $this->m_strNote;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setCasePaperId( $CasePaperId ){
		$this->m_intCasePaperId = $CasePaperId;
	}

	public function setDepartmentId( $DepartmentId ){
		$this->m_intDepartmentId = $DepartmentId;
	}

	public function setDoctorId( $DoctorId ){
		$this->m_intDoctorId = $DoctorId;
	}

	public function setDiagnosisId( $DiagnosisId ){
		$this->m_intDiagnosisId = $DiagnosisId;
	}

	public function setNextVisitDate( $NextVisitDate ){
		$this->m_strNextVisitDate = $NextVisitDate;
	}

	public function setMedicianName( $MedicianName ){
		$this->m_strMedicianName = $MedicianName;
	}

	public function setQuantity( $Quantity ){
		$this->m_intQuantity = $Quantity;
	}

	public function setComapanyName( $ComapanyName ){
		$this->m_strComapanyName = $ComapanyName;
	}

	public function setNote( $Note ){
		$this->m_strNote = $Note;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into MEDICAL_PERCEPTIONS (patient_id, case_paper_id, department_id, doctor_id, diagnosis_id, next_visit_date, medician_name, quantity, comapany_name, note, created_by, created_on) values (" . $this->getPatientId() . ", " . $this->getCasePaperId() . ", " . $this->getDepartmentId() . ", " . $this->getDoctorId() . ", " . $this->getDiagnosisId() . ", '" . $this->getNextVisitDate() . "', '" . $this->getMedicianName() . "', " . $this->getQuantity() . ", '" . $this->getComapanyName() . "', '" . $this->getNote() . "', " . $this->getCreatedBy() . ", now() )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE MEDICAL_PERCEPTIONS set  case_paper_id= " . $this->getCasePaperId() . ", department_id= " . $this->getDepartmentId() . ", doctor_id= " . $this->getDoctorId() . ", diagnosis_id= " . $this->getDiagnosisId() . ", next_visit_date= '" . $this->getNextVisitDate() . "', medician_name= '" . $this->getMedicianName() . "', quantity= " . $this->getQuantity() . ", comapany_name= '" . $this->getComapanyName() . "', note= '" . $this->getNote() . "', created_by= " . $this->getCreatedBy() . ", created_on = created_on where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM medical_perceptions WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'medical_perceptions'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}